package com.xk.meeting.back.controller;

import com.xk.meeting.entity.Regform;
import com.xk.meeting.entityutils.ApplyList;
import com.xk.meeting.entityutils.ListPage;
import com.xk.meeting.entityutils.RegformList;
import com.xk.meeting.service.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/back/regformList")
public class RegformListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String currentPage = request.getParameter("currentPage");
        RegformService regformService = new RegformServiceImpl();
        int rows = 10;
        int totalPage = regformService.getTotalPage(rows);
        if(currentPage == null || Integer.parseInt(currentPage) < 1){
            currentPage = "1";
        }
        if(totalPage != 0 && Integer.parseInt(currentPage) > totalPage){
            currentPage = totalPage+"";
        }

        ListPage<RegformList> listPage = regformService.getApplyList(Integer.parseInt(currentPage),rows);


        request.setAttribute("listPage",listPage);
        request.getRequestDispatcher("regform.jsp").forward(request,response);
    }
}
